package com.stu.stusystem.util;

import java.util.regex.Pattern;

/**
 * @author: cxt
 * @time: 2021/6/29
 * 简单的字符串工具类
 */
public class StrUtil {

    /**
     * 隐藏身份证号中间6位
     */
    public static String hideSix(String str) {
        if (str == null || "".equals(str)) {
            return "";
        }
        if (str.length() == 18) {
            return str.replaceAll("(\\d{6})\\d{6}(\\w{6})", "$1******$2");
        } else {
            return str.replaceAll("(\\d{5})\\d{5}(\\w{5})", "$1*****$2");
        }
    }


    /**
     * 判断是否是隐藏身份证号
     */
    public static boolean judgeIdCard(String idCard) {
        String pattern;
        if (idCard.length() == 18) {
            pattern = "(^\\d{6})(\\*{6})(\\w{6})";
        } else {
            pattern = "(^\\d{5})(\\*{5})(\\w{5})";
        }
        return Pattern.matches(pattern, idCard);
    }
}